<?php
/**
 * 自动表单字典
 * Enter description here ...
 * @author nijn
 *
 */
class AutoFormDictionary {

		
	static public function readConfig() {
		static $config = array();
		if (empty($config)) {
			$config =  include Yii::app()->basePath.'/config/autoForm/dictionary.php';	
		}
		return $config;
	}
	
	/**
	 * 过滤字段
	 * Enter description here ...
	 * @param unknown_type $attributes
	 */
	static public function filterAttributes($attributes) {
		$config = self::readConfig();
		foreach ($attributes as $key=>$one) {
			if (in_array($one, $config['filter'])) {
				unset($attributes[$key]);
			}
		}
		return $attributes;
	}
	
	/**
	 * 自动input
	 * Enter description here ...
	 * @param unknown_type $attributes
	 */
	static public function autoInput($attributes) {
		$config = self::readConfig();
		foreach ($attributes as $key => $one) {	
			$pregKey = preg_replace('/^\S+\./', '', $key);
			if (array_key_exists($pregKey, $config['autoInput'])) {
				$attributes[$key] = $config['autoInput'][$pregKey];
			}
		}
		return $attributes;
	}
}

?>